package com.qububu.emporium.goods.dto;

import java.util.Arrays;

import com.qububu.utils.SystemUtil;

/**
 * 商品大致信息
 * */
public class GoodsAboutDto {
	
	private String goodsId;
	
	private String goodsName;
	
	private String goodsPicUrl;
	
	private String goodsPrice; // 商品价格
	
	private int goodsUseNum;

	private GoodsType goodsType;
	
	public int getGoodsUseNum() {
		return goodsUseNum;
	}

	public void setGoodsUseNum(int goodsUseNum) {
		this.goodsUseNum = goodsUseNum;
	}
	
	public GoodsType getGoodsType() {
		return goodsType;
	}

	public void setGoodsType(GoodsType goodsType) {
		this.goodsType = goodsType;
	}

	public String getGoodsId() {
		return goodsId;
	}

	public String getGoodsPicUrl() {
		return goodsPicUrl;
	}

	public void setGoodsPicUrl(String goodsPicUrl) {
		this.goodsPicUrl = goodsPicUrl;
	}

	public String getGoodsPrice() {
		return goodsPrice;
	}

	public void setGoodsPrice(String goodsPrice) {
		this.goodsPrice = goodsPrice;
	}
	

	public String getGoodsName() {
		return goodsName;
	}

	public void setGoodsName(String goodsName) {
		this.goodsName = goodsName;
	}

	/**
	 * @param goodsId加密型Id
	 */
	public GoodsAboutDto(String goodsId){
		this.goodsId = goodsId;
	}
	/**
	 * @param goodsId真正的goodsId
	 */
	public GoodsAboutDto(Long goodsId){
		this.goodsId = SystemUtil.encrypt(String.valueOf(goodsId));
	}
	
	/**
	 * 商品类型, 
	 * */
	public enum GoodsType {
		MEAT_DIET(0), // 荤菜
		VEGETABLE(1), // 素菜
		SOUP(2), // 汤
		SPECIALITY(3); // 特产
		
		private int intValue;
		
		private GoodsType(int intValue) {
			this.intValue = intValue;
		}

		public static GoodsType getType(String strValue) {
			try {
				GoodsType type = valueOf(strValue);
				return type;
			}
			catch(Exception ex) {
				throw new IllegalArgumentException("Value '" + strValue + "' is not allowed in GoodsType. Only "
						+ Arrays.toString(GoodsType.values()) + " are allowed."
						);
			}
		}
		
		public static GoodsType getType(int intValue) {
			for (GoodsType elem : GoodsType.values()) {
				if (elem.toIntValue() == intValue) {
					return elem;
				}
			}

			throw new IllegalArgumentException("Value '" + intValue
					+ "' is not allowed in GoodsType.");
		}
		
		public int toIntValue() {
			return intValue;
		}
	}

}
